<%@ page import="java.util.*,merlin.beans.*,merlin.dao.*,merlin.managers.*,merlin.servlets.*,merlin.utils.*" errorPage="mr_errhandler.jsp" %>

<%
	ApplicationResources resource = ApplicationResources.getInstance();

	String separatorString = resource.getProperty("separatorString");
	String separatorPattern = resource.getProperty("separatorPattern");
%>

<%
	String adgroup;
	String keywd;

	if (request.getParameter("grp") == null) {
	    adgroup="";
	} else {
	    adgroup=request.getParameter("grp");
	}

	if (request.getParameter("kw") == null) {
	    keywd="";
	} else {
	    keywd=request.getParameter("kw");
	}

    DbResultSet dbRes  = null;
	if(adgroup != null && ! adgroup.trim().equals("") && !"empty".equals(adgroup)){
		dbRes  = ReportTitlesManager.getGoogleLandingPageResult(keywd.toUpperCase());
		// Uncomment the loop to see the results resturned.
		/*
		for(int i=0;i<dbRes.size();i++){
			ReportTitlesBean bean = (ReportTitlesBean)dbRes.get(i);
			System.out.println(bean.getReportTitlesId() + " : " + bean.getReportTitle() + " : " + bean.getScore());
		}
		*/
		// put the result into the request
		request.setAttribute("reportDetails",dbRes);
	}
%>

<HTML>
<HEAD>
<TITLE><%= adgroup %> Industry Reports : <%= keywd %></TITLE>
<META name="description" content="<%= keywd %>. Books and searchable database containing detailed information and the latest data. <%= adgroup %> reports from Merlin Scott Associates. Free updates on all reports." />
<META name="keywords" content="<%= keywd %>, <%= adgroup %>"
<link href="mr_css/master.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
	li {list-style:none;}
	p {text-align:justify;}
	h2 {font-size:12px;}
	.justGreen {color: #418769;}
-->
</style>

<script>
		function isBlank(str){
			var len = str.length;
			if(len==0)return true;	// zero-length string
			for(i=0;i<len;i++){
				if(str.charAt(i) !=' ' && str.charAt(i) !='\n')return false; //some character is there
			}
			return true;
		}

		function transferCompany(lstFrom,lstTo,isDuplicacyChecked){
			try{
				var index = lstFrom.selectedIndex;
				if(index == -1){
					alert("Select a company to add");
					return;
				}
				// check if the company already exists in the selected companies list.
				var exists = false;
				if(isDuplicacyChecked){
					var valCompany = lstFrom.options[index].value;
					var lstTolen = lstTo.length;
					for(j=0;j<lstTolen;j++){
						if(valCompany == lstTo.options[j].value){
							alert("Company already selected");
        					exists = true;
		       				lstFrom.options[index].selected = false;
							break;
	    		    	}
    	   			}
    	   		}
		        if(! exists){
					// add the company to the list
	    		    var aOption = document.createElement("OPTION");
					aOption.text = lstFrom.options[index].text;
					aOption.value = lstFrom.options[index].value;
					// browser specific addition, different in Mac Safari.
					if(navigator.userAgent.indexOf("Safari") > -1){
						// Mac Safari
						lstTo.add(aOption);
					}else{
						// other browsers.
						lstTo.options.add(aOption);
					}

					// and remove it from the other
					lstFrom.remove(index);

                    // sort the data.
					sortSelect(lstTo);
				}
			}catch(e){
				alert("transferCompany : " + e.message);
			}
		}
        	// sort function - ascending (case-insensitive)
        function sortFuncAsc(record1, record2) {
	        var value1 = record1.optText.toLowerCase();
    	    var value2 = record2.optText.toLowerCase();
        	if (value1 > value2) return(1);
            if (value1 < value2) return(-1);
	        return(0);
    	}

	    // sort the select object in ascending order.
		function sortSelect(selectToSort) {
			try{
				// copy options into an array
			    var myOptions = new Array();
				for (var loop=0; loop<selectToSort.options.length; loop++) {
					myOptions[loop] = { optText:selectToSort.options[loop].text, optValue:selectToSort.options[loop].value };
				}

				// sort array
				myOptions.sort(sortFuncAsc);

				// copy sorted options from array back to select box
				selectToSort.options.length = 0;

				// browser identification
				var isSafari =	(navigator.userAgent.indexOf("Safari") > -1)? true: false;

				for (var loop=0; loop<myOptions.length; loop++) {
					var optObj = document.createElement('option');
					optObj.text = myOptions[loop].optText;
					optObj.value = myOptions[loop].optValue;
					if(isSafari){
						selectToSort.add(optObj);
					}else{
						selectToSort.options.add(optObj);
					}
				}
			}catch(e){
				alert("sortSelect : " + e.message);
			}
		}

		function radOrderMethodClick(frm){
			if (frm.lstSelectedReports.options.length > 0)
				frm.btnYourDetails.disabled = false;
		}

		function submitFormForSearch(frm){
			// sanity check
			if(isBlank(frm.txtSearch.value)){
				alert("Enter search text");
				frm.txtSearch.focus();
				return false;
			}

			var reportTitles ="";
			var lstLen = frm.lstSelectedReports.length;
			if(lstLen> 0){
   				for(i=0;i < lstLen - 1;i++){
					reportTitles += frm.lstSelectedReports.options[i].value + "<%= separatorString %>" + frm.lstSelectedReports.options[i].text + "<%= separatorString %>";
				}
				reportTitles += frm.lstSelectedReports.options[lstLen-1].value + "<%= separatorString %>" + frm.lstSelectedReports.options[lstLen-1].text;
			}
			frm.hidSelectedReports.value=reportTitles;
			frm.mode.value="searchReportsByReportDesc";
			frm.action = "merlin";
			frm.submit();
			return true;
		}

		function submitFormForDetails(frm){
			// sanity check

			// find if any of the radio buttons are checked or not.
			if(frm.radOrderMethod[0].checked == false && frm.radOrderMethod[1].checked == false){
				alert("You must select one mode of providing your details");
				return;
			}
            // find if any of the reports is being selected or not.
			if(frm.lstSelectedReports.length==0){
				alert("You must select at least one report before you can continue to this page.");
				return;
			}

			var reportTitles ="";
			var lstLen = frm.lstSelectedReports.length;
			if(lstLen> 0){
   				for(i=0;i < lstLen - 1;i++){
					reportTitles += frm.lstSelectedReports.options[i].value + "<%= separatorString %>" + frm.lstSelectedReports.options[i].text + "<%= separatorString %>";
				}
				reportTitles += frm.lstSelectedReports.options[lstLen-1].value + "<%= separatorString %>" + frm.lstSelectedReports.options[lstLen-1].text;
			}
			frm.hidSelectedReports.value=reportTitles;

			//determine the order method and redirect accordingly
			if(frm.radOrderMethod[0].checked){
				// Contact Details
				frm.action="mr_provideContactDetails.jsp";
			}else{
				// payment Details
				frm.action = "mr_reportSelection.jsp";
			}
  			frm.submit();
			return true;
		}
	</script>
</HEAD>

<BODY>

<table width="750px" border="0" cellspacing="0" cellpadding="0">
<!-- HEADER -->
	<tr>
		<td height="20" colspan="3" class="topnav">		</td>
	</tr>
	<tr>
		<td height="107" colspan="3" background="mr_images/headerMain.gif">&nbsp;</td>
	</tr>
	<tr>
		<td height="25" colspan="3" background="mr_images/nav-banner.jpg" style="vertical-align:top">
			<div id="linkList">
				<li><span class="bump"><a href="home.jsp" target="_top">Home</a></span></li>
				<li><a href="enquiries.jsp" target="_top">700 Industry Reports</a></li>
				<li><span class="nudge"><a href="contactus.jsp" target="_top">Contact Us</a></span></li>
		  </div>		</td>
	</tr>
<!-- END HEADER -->

<!-- MAIN BODY -->
	<tr>
	  <td width="550">
		  <div id="orangeBar">
		    <h1 class="style2"><%= adgroup %> Market Trends, Statistics and Analysis</h1>
		  </div>
		  <p>Merlin Scott Associates Limited publish over 700 industry reports in <a href="#book">book</a> (&pound;195) or <a href="#book">searchable database</a> (&pound;245) form. The <%= adgroup %> industry report benchmarks company and industry performance, analyses market trends and can be used for mergers and acquisition short listing. Our <%= adgroup %> market research is updated every two weeks to provide the latest financial analysis available based on the information at Companies House.</p>
		  <div id="greenBar">
		    <h2><a name="top"></a>Start Here</h2>
		  </div>
	    <!--
		*****************INSERT DATABASE CODE HERE**********************
		If the 'adgroup' variable specifies a certain industry, automatically pull the most relevant reports for that industry,
		similar to the way done on the page: http://www.merlinscottassociates.co.uk/MSAL/searchContent.jsp, with the following changes:

		Step 1 on this page should actually be the step 2 from the searchContent.jsp page, with the wording changed to
		"Based on your search for <%= keywd %>, we found the following reports that are most relevant to your query.
		Click on the report titles to select those of potential interest."

		Step 2 on this page should be step 1 from the searchContent.jsp page, with the wording changed to
		"Search for additional reports by entering a keyword in the title (eg "Insurance" for all reports on Insurance Intermediaries)."
		 Not sure if we should include the link to "view all report titles", as that could distract visitors.
		 The list boxes can be made shorter - 2-3 rows.

		Step 3 remains the same, except the button needs to be made bigger, and instead of "your details" it should just say "next", or "go".
		-->

	<form method="POST" name="searchFrm" onsubmit=" return submitFormForSearch(this)">
		<input type="hidden" name="mode" value="searchReportsByReportDesc">
		<input type="hidden" name="hidSelectedReports" value="">
		<input type="hidden" name="pageName" value="lp_google.jsp">
		<input type="hidden" name="emailFrom" value="Website Search">

		<p>
		<table>
			<tr>
				<td>
					<br>Based on your search for <%= keywd %>, we found the following reports that are most relevant to your query.<em><br>(Click on a report title to select those of potential interest)</em>.
				</td>
				<td style="padding: 33px 0px 0px;">The reports listed here are the titles you have selected.<em><br>(Click to remove a report)</em>.
				</td>
			</tr>
			<tr>
				<td>
					<select name="lstSearchedReports" multiple size="5" onchange="transferCompany(this,this.form.lstSelectedReports,true)" style="width: 300px;">
			  		<%
			     		dbRes = (DbResultSet)request.getAttribute("reportDetails");
			     		if(dbRes != null){
			     			for(int i=0;i<dbRes.size();i++){
			     				ReportTitlesBean bean = (ReportTitlesBean)dbRes.get(i);
								out.println("<option value=\"" + bean.getReportTitlesId() + "\">" + bean.getReportTitle() + "</option>");
			     			}
				   		}
					%>
					</select>
				</td>
				<td>
					<select name="lstSelectedReports" multiple size="5" onchange="transferCompany(this,this.form.lstSearchedReports,false)" style="width: 300px;">
			  		<%
			  			// look for "hidSelectedReports" in both request.getAttribute() & request.getParameter()
			  			String selectedReports = request.getParameter("hidSelectedReports");
			  			if(selectedReports == null){
			  				selectedReports = (String) request.getAttribute("hidSelectedReports");
			  			}
			  			if(selectedReports != null && selectedReports.length() > 0){
					  		String array[] = selectedReports.split(separatorPattern);
					  		int tokens = array.length;
			  				for(int i=0;i<tokens - 1;i+=2){
					  			String reportNumber = array[i];
					  			String reportName = array[i+1];
			             		out.println("<option value=\"" + reportNumber + "\">" + reportName + "</option>");
					  		}
			        	}
			  		%>
					</select>
				</td>
			</tr>
			<tr>
				<td colspan="2">
				<!-- If the 'adgroup' variable is set to 'empty', or does not specify an industry, the search box should be shown as below -->
				  <br>&nbsp;<br>
				  	<%
				  		if((dbRes != null && dbRes.size() > 0) || (selectedReports != null && selectedReports.length() > 0)){
				  	%>
				  	Search for additional reports by entering a keyword in the title (eg "Insurance" for all reports on Insurance Intermediaries).
					<%
						}else{
					%>
					To purchase a report for any industry start by entering the name of the industry you are interested in, and then click "Go". For example, enter "Insurance" for all reports on Insurance Intermediaries.
					<%
						}
					%>

				    <input name="txtSearch" style="text-transform: uppercase;" value="" type="text">
				      <!--<a onClick="document.searchFrm.submit()" onMouseOver="this.style.cursor='hand'" onMouseOut="this.style.cursor='default'"><img src="../MSAL/new-images/search-go.jpg" alt="Search" width="30" height="20" title="Search" /></a>-->
				      <input type="image" src="../MSAL/new-images/search-go.jpg" alt="Search" width="30" height="20" title="Search" />
			    <!-- END Search Box code -->
				</td>
			<tr>
				<td colspan="2">
					<input name="radOrderMethod" value="S" type="radio">Send me order forms for the reports I have selected showing the companies analysed<br>
					<input name="radOrderMethod" value="C" type="radio">I wish to purchase the reports I have selected using my credit card
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<input name="btnYourDetails" class="input" value="Your Details" onclick="submitFormForDetails(this.form)" style="font-size: 11px; width: 130px;" type="button">
				</td>
			</tr>
		</table>
	</form>
		  <h2 class="subhead">Why buy from Merlin Scott Associates?</h2>
		  <ul>
		    <li>:: Analysis of the latest real data available from the <%= adgroup %> industry</li>
              <li>:: Latest 4 years of accounts for all firms (to spot financial trends)</li>
              <li>:: Searchable database enables viewing, exporting or printing your own analysis</li>
              <li>:: Industry statistics based on analysis of relevant companies</li>
              <li>:: Free updates include use of our website lookup database of 2.6 million UK firms</li>
              <li>:: Ratio analysis, performance graphs for every firm</li>
              <li>:: View company rankings in the <%= adgroup %> market</li>
              <li>:: Reports include industry averages for performance benchmarking</li>
              <li>:: Monitor changes as new results are filed</li>
	      </ul>
		  <p>More than 20,000 customers have subscribed to our full industry analysis to keep a keen eye on their market sector.</p>
		  <table width="550" border="0" cellspacing="0" cellpadding="0">
		    <tr valign="top">
		      <td width="265">
		        <p><a href="book.jsp"><img src="new-images/Book-thumbnailMain.jpg" alt="<%= keywd %> Printed Report" width="265" height="196" border="0"></a></p>
                  <p class="subhead"><a name="book"></a>Books @ &pound;195</p>
                  <p>&bull; Up to 700 firms covered<BR>
                    &bull; Latest accounts incorporated<BR>
                    &bull; Colour graphs for easy trend analysis<BR>
                    &bull; Industry Analysis &amp; Industry Averages<BR>
                    &bull; Industry Trends &amp; Industry Ratios<BR>
                    &bull; Free addition of firms<BR>
                  &bull; Free Updates</p>			    </td>
			    <td width="20">&nbsp;</td>
			    <td width="265">
				    <p><em><a href="database.jsp"><img src="new-images/CD-thumbnailMain.jpg" alt="<%= keywd %> Software" width="260" height="196" border="0"></a></em></p>
                    <p class="subhead">Searchable Database @ &pound;245</p>
                    <p>&bull; Coverage of entire industry<BR>
                      &bull; Geographic searches<BR>
                      &bull; Financial searches<BR>
                      &bull; View or print your own reports<BR>
                      &bull; Data is exportable eg mailing lists<BR>
                      &bull; You can combine industry sectors<BR>
                      &bull; Latest accounts incorporated<BR>
                      &bull; Industry Analysis &amp; Industry Averages<BR>
                      &bull; Industry Trends &amp; Industry Ratios<BR>
                      &bull; Free addition of firms<BR>
                    &bull; Free Updates</p>			    </td>
			  </tr>
      </table>
      <p><a href="#top">Back to top</a></p>
      <p>The data presented on this page were based on your search for <%= keywd %>. Please use the search function to find other industry statistics, market trends, and analysis reports. Alternatively, please feel free to call us on 01369 840 643 for any further information you require.</p></td>
      <td width="20">&nbsp;</td>
	  <td width="180"><img src="new-images/business-people.gif" alt="<%= keywd %>" width="180" height="270" border="1" style="border-color:#999999">
	    <div id="LCexisting">
	<h5>Customer Testimonials</h5></div>
		<p>"<em>A very thorough and well presented report that will prove very useful
	    for our traders and financial people over the coming year.
	    Thank you for despatching this report so quickly</em>"</p>
        <p class="justGreen">Alan Thompson<br>
        CEO, Towers Thompson</p>
        <p>&quot;<em>We found the Merlin Associates' financial analysis software and reports extremely beneficial to our business in a number of ways &ndash; both when
  starting up and several years later .</em>
  All in all, for me its money well spent.&quot;</p>
        <p class="justGreen">          Nic Walsh,<br>
          Director,
        Guitar Heaven Ltd</p>
        <p>&quot;<em>Merlin Scott's cost effective printed reports show me what is going on
          in
          the industry.  They are presented in a clear and helpful manner with
          all the
          detail and comparative data that I need.  I also find the 24 hour <br>
        on-line summary results facility a great boon for rapid assessment of the scale
        and
      financial position of any company registered at Companies House.</em>&quot;</p>
        <p class="justGreen">Chris Woods<br>
          Chairman,
          ACW Technology</p>
        <p><br>
        </p>
        </div>
      </td>
	</tr>
<!-- END MAIN BODY -->

<!-- FOOTER -->
	<tr>
		<td colspan="3">
		  <span style="float:right; padding: 10px 0 10px 0; font-size: 9px;"><a href="privacy.jsp">Privacy Policy</a></span>
		  <div id="footer">
			<a href="#">Copyright&copy; 2007 Merlin Scott Associates Limited. All Rights Reserved<br />
			Dunselma Castle, Strone, Dunoon, Argyll, PA23 8RU<br />
			Company Registration Number 02810804</a>		  </div>		</td>
	</tr>
<!-- END FOOTER -->
</table>

</BODY>
</HTML>

<%
	session.invalidate();
%>